package com.renne.email.controller;

import java.util.List;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.renne.common.core.controller.BaseController;
import com.renne.common.core.domain.AjaxResult;
import com.renne.common.core.page.TableDataInfo;
import com.renne.common.annotation.Log;
import com.renne.common.enums.BusinessType;

import com.renne.email.domain.MailItemQuery;
import com.renne.email.domain.MailItemVo;
import com.renne.email.service.IMailItemService;


/**
 * 邮件明细Controller
 *
 * @author LiuYu
 * @date 2024-07-26
 */
@Tag(name = "mail-item-controller", description = "邮件明细")
@RestController
@RequestMapping("/email/item")
public class MailItemController extends BaseController {

    @Autowired
    private IMailItemService mailItemService;


    /**
     * 查询邮件明细列表
     */
    @GetMapping("/list")
    @Operation(summary = "查询邮件明细列表")
    public TableDataInfo list(MailItemQuery query) {
        startPage();
        List<MailItemVo> list = mailItemService.getMailItemVoList(query);
        return getDataTable(list);
    }

    /**
     * 获取邮件明细详细信息
     */
    @GetMapping("/{mailItemId}")
    @Operation(summary = "查询邮件明细详细")
    public AjaxResult getById(@Parameter(description = "主键ID") @PathVariable("mailItemId") String mailItemId) {
        return success(mailItemService.getMailItemVoById(mailItemId));
    }

    /**
     * 新增邮件明细
     */
    @PostMapping
    @Log(title = "邮件明细", businessType = BusinessType.INSERT)
    @Operation(summary = "新增邮件明细")
    public AjaxResult add(@RequestBody MailItemVo mailItemVo) {
        return toAjax(mailItemService.saveMailItemVo(mailItemVo));
    }

    /**
     * 修改邮件明细
     */
    @PutMapping
    @Log(title = "邮件明细", businessType = BusinessType.UPDATE)
    @Operation(summary = "修改邮件明细")
    public AjaxResult update(@RequestBody MailItemVo mailItemVo) {
        return toAjax(mailItemService.updateMailItemVo(mailItemVo));
    }

    /**
     * 删除邮件明细记录
     */
    @DeleteMapping("/{mailItemId}")
    @Log(title = "邮件明细", businessType = BusinessType.DELETE)
    @Operation(summary = "删除邮件明细")
    public AjaxResult delete(@Parameter(description = "主键ID") @PathVariable("mailItemId") String mailItemId) {
        return toAjax(mailItemService.deleteMailItemById(mailItemId));
    }

    /**
     * 删除邮件明细记录
     */
    @PostMapping("/sendEmail/{mailItemIds}")
    @Log(title = "邮件明细", businessType = BusinessType.UPDATE)
    @Operation(summary = "根据邮件明细ID发送邮件")
    public AjaxResult sendEmail(@Parameter(description = "主键ID") @PathVariable("mailItemIds") String mailItemIds) {
        mailItemService.sendEmailByMailItemIds(mailItemIds);
        return AjaxResult.success();
    }
}
